<?php
namespace Mob \ Controller;

use Think \ Controller;
use Think \ Hook;
header('Content-type: text/html; charset=utf8');
class ActivityController extends BaseController {

    private $UserInfo;

	public function _initialize() {
		parent :: _initialize();
		$this->_top_menu_list = array (
			'left' => array (
				array (
					'type' => 'home',
					'href' => U('Mob/Activity/activitymap'
				)
			),


		), 'center' => array (
			'title' => '知道'
		));
		if (is_login()) {


	  $this->_top_menu_list['right'][] = array (
					'type' => 'edit',
					'href' => U('Mob/Activity/creator'
				));

	  /*
			if (check_auth('Mob/Task/addActivity')) {
				$this->_top_menu_list['right'][] = array (
					'type' => 'edit',
					'href' => U('Mob/Task/addActivity'
				));
			} else {
				$this->_top_menu_list['right'][] = array (
					'type' => 'edit',
					'info' => '你没有发布任务权限！'
					//'info' =>M()->getLastSql()
				);
			}
	   */
		} else {
			$this->_top_menu_list['right'][] = array (
				'type' => 'edit',
				'info' => '登录后才能操作！'
			);
	  $redirect = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
       $redirect= urlencode($redirect);
	//	$this->redirect('Member/index');
	    $this->redirect('WxUser/loginPortal',array('redirect'=>$redirect));

		}
		//dump($this->_top_menu_list);exit;



		$this->UserInfo = query_user(array('nickname', 'avatar64', 'uid'), $v['uid']);
		$this->setMobTitle('知道');
		$this->assign('top_menu_list', $this->_top_menu_list);
	//print_r($this->_top_menu_list);
	}

	/**
	 * 主页面显示
	 */
	public function index() {


    $this->display();



	}

   public function creator()
   {

    if(IS_POST)
    {

     $Uid = get_uid();
     $Title = I('post.Title','','string');
     $longitude = I('post.longitude','','float');
     $latitude = I('post.latitude','','float');
     $actLongitude = I('post.actlongitude','','float');
     $actLatitude = I('post.actlatitude','','float');
     $activityType = I('post.Type','','int');
     $isPay = I('post.isPay','','int');
     $amount = I('post.amount','','int')*100;
     $people = I('post.people','','int');
     $positiontype = I('post.positiontype',1,'int');


     $activity =D('Activity');
     $id = $activity->creationActivity($Uid,$Title,$activityType,$actLongitude,$actLatitude,$latitude,$longitude,$positiontype,$isPay,$amount,$people); //创建活动信息
     if($id)
     {
     $paymode='微信支付';
     $order = D('Orders');
     if($activityType==1)
     {
     $orderType=3;
     }else
     {
     $orderType=4;
     }
     if($isPay==1)
     {
     $orderId=$order->AcceptanceOrder($paymode,$amount,$Uid,$id,$orderType);
     if($orderId)
     {
     $redpack = D('RedPack');
     $redpackId = $redpack->creatorRedPack($Uid,$amount,$people,2,$id,$orderId);
     }
     if($redpackId)
     {
     $data = array('paySerialno'=>$redpackId,'orderId'=>$orderId);
     $activity->updateActivityInfo($id,$data);
     }

     }



     switch($activityType)
     {

     case 1:

     $this->redirect('Notice/newsend',array('activityId'=>$id));

     break;

     case 2:

     break;

     case 3:

     break;

     }
     }

    }else
    {
    if(is_login()==0)
    {
    $this->redirect('member/index');
    }else
    {
     $this->display();
    }

    }
   }

  public function settingActivity()
  {
  $activityId = I('activityId','','string');

   $act =D('Activity');
   $activity = $act->queryActivity($activityId);


   if($activity)
   {
   	$uid = get_uid();

   	if($activity['sponsorUid']!=$uid)
   	{
    print_r('Invalid Argument!');

   	}
   	elseif($activity['status']==1)
   	{
   	print_r('Task has been released!');
   	}elseif($activity['isPay']==2)
   	{

    $res= $act->releaseActivity($activityId,$uid);

     $this->redirect('Activity/actDetails',array('actId'=>$activityId));


   	}elseif($activity['isPay']==1)
   	{
    $Serialno= $activity['activityId'];
    $Money=$activity['amount'];
    $OrderId= $activity['orderId'];
    $PayMode='微信支付';


    $this->redirect('Portal/PayMent/index',array('businessId'=>$Serialno,'Money'=>$Money,'PayMode'=>$PayMode,'OrderID'=>$OrderId));

   	}
   }
  }



  public function activityHall()
  {



      if (IS_POST){
          $latitude = I('post.latitude');
          $longitude = I('post.longitude');
          $distance=50000;

          $position = array('latitude'=>$latitude,'longitude'=>$longitude);

          $act=D('Activity');
          $activity = $act->activityHall($position,$data,$distance,$sortType);




          foreach($activity as &$v)
          {

              $v['user'] = query_user(array('nickname', 'avatar64', 'avatar32','uid'), $v['sponsorUid']);
              if($v['activityType']==1)
              {
                  $Notice=  D('Notice')->queryNotice($v['businessId']);
                  $v['content']=$Notice['content'];
                  $v['type']=$Notice['type'];
                  $v['data']=$Notice['data'];
                  if($v['type']==="repost"){
                      $v['content']=parse_br_nb( $v['content']);
                      $v['content']= A('Mob/WeiboType')->fetchRepost($v);
                  }else if($v['type']==="xiami") {
                      $v['content'] = parse_br_nb($v['content']);
                      $v['content'] = Hook::exec('Addons\\Insert' . ucfirst($v['type']) . '\\Insert' . ucfirst($v['type']) . 'Addon', 'fetch' . 'Mobile' . ucfirst($v['type']), $v);
                  }else if($v['type']=="video"){
                      $v['content'] = parse_br_nb($v['content']);
                      $v['content'] = Hook::exec('Addons\\Insert' . ucfirst($v['type']) . '\\Insert' . ucfirst($v['type']) . 'Addon', 'fetch' . ucfirst($v['type']), $v);

                  }else{

                      $v['content'] = parse_weibo_mobile_content($v['content']);
                      $v['content']['wenben'] = str_replace('<br/>', '',$v['content']['wenben']);
                      $v['content']['wenben']= str_replace('&nbsp;', '', $v['content']['wenben']);
                      $v['content']['wenben'] = contentsubstr($v['content']['wenben'],36);



                  }
                  /*
                  if (empty($v['from'])) {
                      $v['from'] = "网站端";
                  }
                  */
                  $v['data'] = unserialize($v['data']);              //字符串转换成数组,获取微博源ID

                  if ($v['data']['sourceId']) {                        //判断是否是源微博
                      $v['sourceId'] = $v['data']['sourceId'];
                      $v['is_sourceId'] = '1';
                  } else {
                      $v['sourceId'] = $v['id'];
                      $v['is_sourceId'] = '0';
                  }
                  //    $v['sourceId_user'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->find();           //源微博用户名
                  //    $v['sourceId_user'] = $v['sourceId_user']['uid'];
                  //        $v['sourceId_user'] = query_user(array('nickname', 'uid'), $v['sourceId_user']);

                  //    $v['sourceId_content'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->field('content')->find();          //源微博内容
                  //    if(!is_null($v['sourceId_content'])){
                  //       $v['sourceId_content'] = parse_weibo_mobile_content($v['sourceId_content']['content']);                                          //把表情显示出来。
                  //    }


                  //      $v['sourceId_repost_count'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->field('repost_count')->find();    //源微博转发数
                  //  $v['sourceId_from'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->field('from')->find();       //源微博来源

                  /*
                 if (empty($v['sourceId_from']['from'])) {
                     $v['sourceId_from'] = "网站端";
                 } else {
                     $v['sourceId_from'] = "手机网页版";
                 }
                */
                  $v['sourceId_img'] = D('Notice')->where(array('status' => 1, 'noticeId' => $v['businessId']))->field('data')->find();    //为了获取源微图片
                  $v['sourceId_img'] = unserialize($v['sourceId_img']['data']);
                  $v['sourceId_img'] = explode(',', $v['sourceId_img']['attach_ids']);        //把attach_ids里的图片ID转出来
                  foreach ($v['sourceId_img'] as &$b) {
                      $v['sourceId_img_path'][] = getThumbImageById($b, 100, 100);                      //获得缩略图
//获得原图
                      $bi = M('Picture')->where(array('status' => 1))->getById($b);
                      if (!is_bool(strpos($bi['path'], 'http://'))) {
                          $v['sourceId_img_big'][] = $bi['path'];
                      } else {
                          $v['sourceId_img_big'][] = getRootUrl() . substr($bi['path'], 1);
                      }
                  }


                  $v['cover_url'] = explode(',', $v['data']['attach_ids']);        //把attach_ids里的图片ID转出来
                  foreach ($v['cover_url'] as &$a) {
                      $v['img_path'][] = getThumbImageById($a, 100, 100);
                      //获得原图
                      $bi = M('Picture')->where(array('status' => 1))->getById($b);
                      if (!is_bool(strpos($bi['path'], 'http://'))) {
                          $v['sourceId_img_big'][] = $bi['path'];
                      } else {
                          $v['sourceId_img_big'][] = getRootUrl() . substr($bi['path'], 1);
                      }
                  }

                  if (in_array($v['id'], $is_zan)) {                         //判断是否已经点赞
                      $v['is_support'] = '1';
                  } else {
                      $v['is_support'] = '0';
                  }

                  if (empty($v['data']['attach_ids'])) {            //判断是否是图片
                      $v['is_img'] = '0';
                  } else {
                      $v['is_img'] = '1';
                  }
                  if (empty($v['sourceId_img']['0'])) {
                      $v['sourceId_is_img'] = '0';
                  } else {
                      $v['sourceId_is_img'] = '1';
                  }
              }elseif($v['activityType']==2)
              {


              }

          }
          $this->ajaxReturn($activity);

      }
else{
    $clatitude = I('latitude','','float'); //从请求中取纬度
    $clongitude = I('longitude','','float');  //从请求中经度
    $csortType = I('sortType',1,'int');

    $this->assign('clongitude',$clongitude);
    $this->assign('clatitude',$clatitude);
    $this->assign('csortType',$csortType);
    //  $this->assign('Activity',$activity);
    $this->display();
}











  }






   private function addActivityCheck()
   {
   //  http://localhost/opensns/index.php?s=/mob/Activity/index/Title/欢迎/isPay/1/activityType/1
   	  $Title = I('Title');
   	  $isPay = I('isPay','','int');
   	  $amount= I('amount','','float');
   	  $peopleNum = I('peopleNum','','int');
      $activityType = I('activityType','','int');
      if(empty($activityType))
      {
       $data['status']=0;
   	    $data['msg']='活动类型不能为空!';
      }
       elseif(empty($Title))
       {
        $data['status']=0;
   	    $data['msg']='标题不能为空!';

       }
       elseif(empty($isPay))
       {
        $data['status']=0;
   	    $data['msg']='是否付费字段为空!';

       }elseif($isPay==1)
       {
       if(empty($amount))
       {

   	   $data['status']=0;
   	   $data['msg']='金额不能为空!';
   	   }elseif(empty($peopleNum))
   	   {
   	   $data['status']=0;
   	   $data['msg']='人数不能为空!';
   	   }
   	   elseif($amount<100)
   	   {
   	   $data['status']=0;
   	   $data['msg']='红包总金额不能少于1元!';
   	   }elseif($amount/$peopleNum<100)
   	   {
       $data['status']=0;
   	   $data['msg']='单个红包金额不能少于1元!';
   	   }else
   	   {
   	   $data['status']=1;

   	   }

       }
     return $data;

   }

  public function actDetails()
  {
  	$activityId = I('actId');

  	if(empty($activityId))
  	{
   $this->redirect('Activity/activityhall');
  	}
  	$uid = get_uid();
  	$act = D('Activity');
  	$act->browseRecord();  //先记录日志
  	$activity = $act->details($activityId);  //取详情

  	if(empty($activity))
  	{
	$this->redirect('Activity/activityhall');
  	}




  	if($activity['isPay']==1)
  	{
  	$activity['RedPack']=D('RedPack')->getRemainRedPack($activity['paySerialno']);

  	}

    $activity['User']= query_user(array('nickname', 'avatar64', 'uid'), $activity['sponsorUid']);
    $activity['releaseDate']=formatDate($activity['releaseTime']);


  	if($activity['sponsorUid']==$uid)
  	{
  	$activity['is_release']	=1;
  	}else
  	{
  	$activity['is_release']	=0;
    $res = D('RedPackRecord')->isApply($activity['paySerialno'],$uid);
   if($res)
   {
   	$activity['is_Apply']=0;
   }else
   {
     $activity['is_Apply']=1;
   }

  	}
  	switch($activity['activityType'])
  	{

  	case 1:
  	$notice = D('Notice');
  	$noticeInfo =$notice->getContents($activity['businessId']);
  	$activity['content']=$noticeInfo['content'];
  	$activity['data']=$noticeInfo['data'];
  	$activity['type']=$noticeInfo['type'];
  	$activity['browsenPersonNum']=$noticeInfo['browsenPersonNum'];
  	$activity['browseNum']=$noticeInfo['browseNum'];



        if($activity['type']==="repost"){
                $activity['content']=parse_br_nb( $activity['content']);
                $activity['content']= A('Mob/WeiboType')->fetchRepost($activity);
            }else if($activity['type']==="xiami") {
                $activity['content'] = parse_br_nb($activity['content']);
                $activity['content'] = Hook::exec('Addons\\Insert' . ucfirst($activity['type']) . '\\Insert' . ucfirst($activity['type']) . 'Addon', 'fetch' . 'Mobile' . ucfirst($activity['type']), $activity);
            }else if($activity['type']=="video"){
                $activity['content'] = parse_br_nb($activity['content']);
                $activity['content'] = Hook::exec('Addons\\Insert' . ucfirst($activity['type']) . '\\Insert' . ucfirst($activity['type']) . 'Addon', 'fetch' . ucfirst($activity['type']), $activity);

            }else{
               //  $activity['content'] = contentsubstr($activity['content']);
                $activity['content'] = parse_weibo_mobile_content($activity['content']);

            }
            /*
            if (empty($v['from'])) {
                $v['from'] = "网站端";
            }
            */
            $activity['data'] = unserialize($activity['data']);              //字符串转换成数组,获取微博源ID

            if ($activity['data']['sourceId']) {                        //判断是否是源微博
                $activity['sourceId'] = $activity['data']['sourceId'];
                $activity['is_sourceId'] = '1';
            } else {
                $activity['sourceId'] = $activity['id'];
                $activity['is_sourceId'] = '0';
            }

             $activity['sourceId_img'] = D('Notice')->where(array('status' => 1, 'noticeId' => $activity['businessId']))->field('data')->find();    //为了获取源微图片
            $activity['sourceId_img'] = unserialize($activity['sourceId_img']['data']);
            $activity['sourceId_img'] = explode(',', $activity['sourceId_img']['attach_ids']);        //把attach_ids里的图片ID转出来
            foreach ($activity['sourceId_img'] as &$b) {
                $activity['sourceId_img_path'][] = getThumbImageById($b, 100, 100);                      //获得缩略图
//获得原图
                $bi = M('Picture')->where(array('status' => 1))->getById($b);
                if (!is_bool(strpos($bi['path'], 'http://'))) {
                    $activity['sourceId_img_big'][] = $bi['path'];
                } else {
                    $activity['sourceId_img_big'][] = getRootUrl() . substr($bi['path'], 1);
                }
            }


            $activity['cover_url'] = explode(',', $activity['data']['attach_ids']);        //把attach_ids里的图片ID转出来
            foreach ($activity['cover_url'] as &$a) {
                $activity['img_path'][] = getThumbImageById($a, 100, 100);
                //获得原图
                $bi = M('Picture')->where(array('status' => 1))->getById($b);
                if (!is_bool(strpos($bi['path'], 'http://'))) {
                    $activity['sourceId_img_big'][] = $bi['path'];
                } else {
                    $activity['sourceId_img_big'][] = getRootUrl() . substr($bi['path'], 1);
                }
            }



            if (empty($activity['data']['attach_ids'])) {            //判断是否是图片
                $activity['is_img'] = '0';
            } else {
                $activity['is_img'] = '1';
            }
            if (empty($activity['sourceId_img']['0'])) {
                $activity['sourceId_is_img'] = '0';
            } else {
                $activity['sourceId_is_img'] = '1';
            }


  	 break;

    case 2:
     break;
    case 3:
    break;
    case 4:
    break;



  	}
        $mapl['businessId'] = array('eq', $activityId);
      $aPage=1;
      $aCount=10;
  	    $comment = D('Comment')->where(array('status' => 1, $mapl))->page($aPage, $aCount)->order('create_time desc')->select();
        $totalCount = D('Comment')->where(array('status' => 1, $mapl))->count();
        if ($totalCount <= $aPage * $aCount) {
            $pid['count'] = 0;
        } else {
            $pid['count'] = 1;
        }
        foreach ($comment as &$k) {
        	$k['create_time']=strtotime($k['create_time']);
            $k['user'] = query_user(array('nickname', 'avatar64', 'uid'), $k['commentUid']);
            $k['rand_title'] = mob_get_head_title($k['uid']);
            $k['content'] = parse_weibo_mobile_content($k['content']);
            if($k['commentUid']==$uid||$activity['sponsorUid']==$uid)
            {
            $k['is_del']=1;
            }else
            {
            $k['is_del']=0;
            }
            if($k['commentUid']==$uid)
            {
                $k['is_huifu']=0;
            }else
            {
                $k['is_huifu']=1;
            }
        }

    // print_r($activity);
    $this->assign('comment',$comment);
      $this->assign('pid',$pid);
    $this->assign('activity',$activity);
    $this->display();








  }
    public function addMoreComment()
    {
        $uid = get_uid();
        $aPage = I('post.page', 1, 'op_t');
        $aCount = I('post.count', 10, 'op_t');
        $sponsorUid = I('post.sponsorUid', '', 'op_t');
        $aId = I('post.id', '', 'op_t');

        $map['businessId'] = array('eq', $aId);
        $comment = D('Comment')->where(array('status' => 1, $map))->page($aPage, $aCount)->order('create_time desc')->select();
        foreach ($comment as &$k) {
            $k['user'] = query_user(array('nickname', 'avatar64', 'uid'), $k['commentUid']);
            $k['rand_title'] = mob_get_head_title($k['uid']);
            $k['content'] = parse_weibo_mobile_content($k['content']);
            $k['create_time']=strtotime($k['create_time']);   //加入时间转换条件
            if($k['commentUid']==$uid||$sponsorUid==$uid)
            {
                $k['is_del']=1;
            }else
            {
                $k['is_del']=0;
            }
            if($k['commentUid']==$uid)
            {
                $k['is_huifu']=0;
            }else
            {
                $k['is_huifu']=1;
            }
        }

        if ($comment) {
            $data['html'] = "";
            foreach ($comment as $val) {
                $this->assign("vl", $val);
                $data['html'] .= $this->fetch("_comment");

                $data['status'] = 1;
            }
        } else {
            $data['stutus'] = 0;
        }
        $this->ajaxReturn($data);
    }

   public function doAddComment()
    {

        if (!is_login()) {
            $this->error('请您先登录', U('Mob/member/index'), 1);
        }
        $uid = get_uid();
        $sponsorUid = I('post.sponsorUid', '', 'op_t');
        $aContent = I('post.content', '', 'op_t');              //说点什么的内容
        $aActId = I('post.actId', 0, 'op_t');             //要评论的微博的ID
        $aBusId = I('post.busId', 0, 'op_t');             //要评论的微博的ID
        $aType = I('post.type', 0, 'intval');             //要评论的微博的ID
        $aCommentId = I('post.comment_id', 0, 'intval');
        $huifuid = I('post.huifuid', '','op_t');             //要评论的微博的ID





        if (empty($aContent)) {
           $this->error('评论内容不能为空。');

        }



      //  $this->checkAuth('Weibo/Index/doComment', -1, '您无微博评论权限。');
      //  $return = check_action_limit('add_weibo_comment', 'weibo_comment', 0, is_login(), true);//行为限制
      //  if ($return && !$return['state']) {
      //      $this->error($return['info']);
     //   }
        $new_id = send_comment($aActId, $huifuid,$aContent,$aType, $aCommentId);        //发布评论
      //  send_comment($businessId, $content,$type, $comment_id = 0)


        $comment = D('Comment')->where(array('status' => 1, 'commentId' => $new_id))->order('create_time desc')->select();

        foreach ($comment as &$k) {
            $k['user'] = query_user(array('nickname', 'avatar64', 'uid'), $k['commentUid']);
            $k['rand_title'] = mob_get_head_title($k['uid']);
            $k['content'] = parse_weibo_mobile_content($k['content']);
            $k['create_time']=strtotime($k['create_time']);   //加入时间转换条件
            if($k['commentUid']==$uid||$sponsorUid==$uid)
            {
                $k['is_del']=1;
            }else
            {
                $k['is_del']=0;
            }
            if($k['commentUid']==$uid)
            {
                $k['is_huifu']=0;
            }else
            {
                $k['is_huifu']=1;
            }
        }

        if ($comment) {
            $data['html'] = "";
            foreach ($comment as $val) {
                $this->assign("vl", $val);
                $data['html'] .= $this->fetch("_comment");

                $data['status'] = 1;
            }
        } else {
            $data['stutus'] = 0;
        }
        $this->ajaxReturn($data);
    }


    public function addComment($id, $user)
    {
        //$id是发帖人的微博ID
        //$uid是发帖人的ID

        $map['id'] = array('eq', $id);
        $weibo = D('Weibo')->where(array('status' => 1, $map))->order('create_time desc')->select();


        foreach ($weibo as &$v) {
            $v['user'] = query_user(array('nickname', 'avatar64', 'uid'), $v['uid']);

            $v['support'] = D('Support')->where(array('appname' => 'Weibo', 'table' => 'weibo', 'row' => $v['id']))->count();

            $v['data'] = unserialize($v['data']);              //字符串转换成数组
            if ($v['data']['sourceId']) {
                $v['sourceId'] = $v['data']['sourceId'];
                $v['is_sourceId'] = '1';
            } else {
                $v['sourceId'] = $v['id'];
                $v['is_sourceId'] = '0';
            }
            $v['sourceId_user'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->find();           //源微博用户名
            $v['sourceId_user'] = $v['sourceId_user']['uid'];
            $v['sourceId_user'] = query_user(array('nickname', 'uid'), $v['sourceId_user']);
            $v['sourceId_content'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->field('content')->find();


            $v['at_user_id'] = $user;

        }
//dump($weibo);exit;
        $this->assign('weibo', $weibo[0]);
        $this->display(T('Application://Mob@Activity/addcomment'));

    }


     public function delComment()
    {
        $comment_id = I('post.commentId', 0, 'op_t');              //接收评论ID
        $act_id = I('post.act-id', 0, 'op_t');                   //接收微博ID

        $act_uid = D('activity')->where(array('status' => 1, 'activityId' => $act_id))->find();//根据微博ID查找微博发送人的UID
        $comment_uid = D('comment')->where(array('status' => 1, 'commentId' => $comment_id))->find();//根据评论ID查找评论发送人的UID

        if (!is_login()) {
            $this->error('请登陆后再进行操作');
        }


        if (is_administrator(get_uid()) || $act_uid['sponsorUid'] == get_uid() || $comment_uid['commentUid'] == get_uid()) {                                     //如果是管理员，则可以删除评论
            $result = D('Comment')->deleteComment($comment_id);
        }
        if ($result) {
            $return['status'] = 1;
        } else {
            $return['status'] = 0;
        //    $return['info'] = '删除失败';

        }
        $this->ajaxReturn($return);
    }

    public function activitymap()
    {

      //  $clatitude = I('latitude','','float'); //从请求中取纬度
      //  $clongitude = I('longitude','','float');  //从请求中经度
   //  $latitude = I('post.latitude','43.821913','float'); //从请求中取纬度
    // $longitude = I('post.longitude','125.27291','float');  //从请求中经度
     //$aPage = I('post.page', 1, 'op_t');
     //$aCount = I('post.count',10, 'op_t');

     //$distance = I('post.distance',20000,'intval');
        /**
        if (IS_AJAX){
            $longitude=$_POST['jingdu'];
            $latitude=$_POST['weidu'];
            $longitude_json=json_decode($longitude,true);
            $latitude_json=json_decode( $latitude,true);
            $distance=50000;
            $position = array('latitude'=>$latitude_json,'longitude'=>$longitude_json);
            $act=D('Activity');
            $activity = $act->activityMap($position,$data,$distance);
            foreach($activity as &$a)
            {
                $a['user'] = query_user(array('nickname', 'avatar32','avatar128', 'avatar256', 'uid','usertype'), $a['sponsorUid']);
            }
            //$this->ajaxReturn($activity);
            echo json_encode($activity, JSON_UNESCAPED_UNICODE);

        }
        **/
        if (IS_POST){
            $latitude = I('post.latitude');
            $longitude = I('post.longitude');
            $distance=50000;
            $position = array('latitude'=>$latitude,'longitude'=>$longitude);
            $act=D('Activity');
            $activity = $act->activityMap($position,$data,$distance);
            foreach($activity as &$a)
            {
                $a['user'] = query_user(array('nickname', 'avatar32','avatar128', 'avatar256', 'uid','usertype'), $a['sponsorUid']);
            }
           // $data0='学号已经被注册过了!';
            $this->ajaxReturn($activity);
            //echo json_encode($activity, JSON_UNESCAPED_UNICODE);

        }else{

            $clatitude = I('latitude','','float'); //从请求中取纬度
            $clongitude = I('longitude','','float');  //从请求中经度
            $zoom= I('zoom','16','float');
            $this->assign('clongitude',$clongitude);
            $this->assign('clatitude',$clatitude);
            $this->assign('zoom',$zoom);
            //$this->assign('activitylist',$activity);
            // echo json_encode($activity, JSON_UNESCAPED_UNICODE);
            $this->display();
        }





    }

    public function myActivity()
    {

     $uid = get_uid();
     $actType = I('post.type',1,'intval');  //1为公告
     $my = D('My');
     $myIssue = $my->actIssue($uid,$actType);
     $myPlayers = $my->actPlayers($uid);
     $this->assign('myIssue',$myIssue);
     $this->assign('myPlayers',$myPlayers);
     $this->display();



    }
    public function actDispay()
    {
    $aActId = I('actId', 0, 'op_t');
    $uid = get_uid();
    $act = D('Activity');
  	$activity = $act->details($aActId);  //取详情
  	switch($activity['activityType'])
  	{

  	case 1:
  	$notice = D('Notice');
  	$noticeInfo =$notice->getContents($activity['businessId']);
  	$activity['content']=$noticeInfo['content'];
  	$activity['data']=$noticeInfo['data'];
  	$activity['type']=$noticeInfo['type'];
  	$activity['browsenPersonNum']=$noticeInfo['browsenPersonNum'];
  	$activity['browseNum']=$noticeInfo['browseNum'];



        if($activity['type']==="repost"){
                $activity['content']=parse_br_nb( $activity['content']);
                $activity['content']= A('Mob/WeiboType')->fetchRepost($activity);
            }else if($activity['type']==="xiami") {
                $activity['content'] = parse_br_nb($activity['content']);
                $activity['content'] = Hook::exec('Addons\\Insert' . ucfirst($activity['type']) . '\\Insert' . ucfirst($activity['type']) . 'Addon', 'fetch' . 'Mobile' . ucfirst($activity['type']), $activity);
            }else if($activity['type']=="video"){
                $activity['content'] = parse_br_nb($activity['content']);
                $activity['content'] = Hook::exec('Addons\\Insert' . ucfirst($activity['type']) . '\\Insert' . ucfirst($activity['type']) . 'Addon', 'fetch' . ucfirst($activity['type']), $activity);

            }else{
               //  $activity['content'] = contentsubstr($activity['content']);
                $activity['content'] = parse_weibo_mobile_content($activity['content']);

            }
            /*
            if (empty($v['from'])) {
                $v['from'] = "网站端";
            }
            */
            $activity['data'] = unserialize($activity['data']);              //字符串转换成数组,获取微博源ID

            if ($activity['data']['sourceId']) {                        //判断是否是源微博
                $activity['sourceId'] = $activity['data']['sourceId'];
                $activity['is_sourceId'] = '1';
            } else {
                $activity['sourceId'] = $activity['id'];
                $activity['is_sourceId'] = '0';
            }

             $activity['sourceId_img'] = D('Notice')->where(array('status' => 1, 'noticeId' => $activity['businessId']))->field('data')->find();    //为了获取源微图片
            $activity['sourceId_img'] = unserialize($activity['sourceId_img']['data']);
            $activity['sourceId_img'] = explode(',', $activity['sourceId_img']['attach_ids']);        //把attach_ids里的图片ID转出来
            foreach ($activity['sourceId_img'] as &$b) {
                $activity['sourceId_img_path'][] = getThumbImageById($b, 100, 100);                      //获得缩略图
//获得原图
                $bi = M('Picture')->where(array('status' => 1))->getById($b);
                if (!is_bool(strpos($bi['path'], 'http://'))) {
                    $activity['sourceId_img_big'][] = $bi['path'];
                } else {
                    $activity['sourceId_img_big'][] = getRootUrl() . substr($bi['path'], 1);
                }
            }


            $activity['cover_url'] = explode(',', $activity['data']['attach_ids']);        //把attach_ids里的图片ID转出来
            foreach ($activity['cover_url'] as &$a) {
                $activity['img_path'][] = getThumbImageById($a, 100, 100);
                //获得原图
                $bi = M('Picture')->where(array('status' => 1))->getById($b);
                if (!is_bool(strpos($bi['path'], 'http://'))) {
                    $activity['sourceId_img_big'][] = $bi['path'];
                } else {
                    $activity['sourceId_img_big'][] = getRootUrl() . substr($bi['path'], 1);
                }
            }



            if (empty($activity['data']['attach_ids'])) {            //判断是否是图片
                $activity['is_img'] = '0';
            } else {
                $activity['is_img'] = '1';
            }
            if (empty($activity['sourceId_img']['0'])) {
                $activity['sourceId_is_img'] = '0';
            } else {
                $activity['sourceId_is_img'] = '1';
            }


  	 break;

    case 2:
     break;
    case 3:
    break;
    case 4:
    break;



  	}
        $mapl['businessId'] = array('eq', $aActId);
        $aPage=1;
        $aCount=10;
  	    $comment = D('Comment')->where(array('status' => 1, $mapl))->page($aPage, $aCount)->order('create_time desc')->select();
        $totalCount = D('Comment')->where(array('status' => 1, $mapl))->count();
        if ($totalCount <= $aPage * $aCount) {
            $pid['count'] = 0;
        } else {
            $pid['count'] = 1;
        }
        foreach ($comment as &$k) {
        	$k['create_time']=strtotime($k['create_time']);
            $k['user'] = query_user(array('nickname', 'avatar64', 'uid'), $k['commentUid']);
            $k['rand_title'] = mob_get_head_title($k['uid']);
            $k['content'] = parse_weibo_mobile_content($k['content']);
            if($k['commentUid']==$uid||$activity['sponsorUid']==$uid)
            {
            $k['is_del']=1;
            }else
            {
            $k['is_del']=0;
            }

        }


    $this->assign('comment',$comment);
        $this->assign('pid',$pid);
    $this->assign('activity',$activity);
    $this->display();



    }

    public function actLoading ()
    {
      $this->display();

    // $latitude = I('post.latitude','43.886841','float'); //从请求中取纬度
   ///  $longitude = I('post.longitude','125.3245','float');  //从请求中经度
    // $this->redirect('Activity/activityhall',array('latitude'=>$latitude,'longitude'=>$longitude));
    }
    public function actmapLoading ()
    {
        $this->display();

        // $latitude = I('post.latitude','43.886841','float'); //从请求中取纬度
        ///  $longitude = I('post.longitude','125.3245','float');  //从请求中经度
        // $this->redirect('Activity/activityhall',array('latitude'=>$latitude,'longitude'=>$longitude));
    }

    public function actLocationMap()
    {
    $latitude = I('get.latitude',null,'float'); //从请求中取纬度
    $longitude = I('get.longitude',null,'float');  //从请求中经度
    $aActId = I('actId', null, 'op_t');







    }





    public function selectMap()
    {

     if(IS_POST)
     {
    $latitude = I('post.latitude',null,'float'); //从请求中取纬度
     $longitude = I('post.longitude',null,'float');  //从请求中经度

     print_r('post.latitude='.$latitude."<br>);" );
     print_r('post.longitude='.$longitude."<br>);" );
     if(empty($latitude))
     {
    $latitude ='43.823261';
    $longitude= '125.279345';
     }


     $aPage = I('post.page', 1, 'op_t');
     $aCount = I('post.count',10, 'op_t');
     $distance = I('post.distance',20000,'intval');
     $position = array('latitude'=>$latitude,'longitude'=>$longitude);

     $act=D('Activity');
     $activity = $act->activityMap($position,$data,$distance);
     foreach($activity as &$a)
     {
    $a['user'] = query_user(array('nickname', 'avatar32','avatar128', 'avatar256', 'uid'), $a['sponsorUid']);
     }
     $this->assign('activitylist',$activity);
     print_r($activity);
     // echo json_encode($activity, JSON_UNESCAPED_UNICODE);
    $this->display();
     }
     else
     {
     $this->display();
     }

    }

}
?>



